#!/bin/bash
# Docker容器日志查看脚本

set -e  # 遇到错误立即退出

# 容器配置
CONTAINER_NAME="edge-cloud-ai"
FOLLOW=${1:-"false"}

echo "📋 查看边缘云端AI训练系统Docker容器日志..."
echo "📦 容器名称: ${CONTAINER_NAME}"
echo ""

# 检查Docker是否运行
if ! docker info >/dev/null 2>&1; then
    echo "❌ Docker未运行或无法访问，请检查Docker服务状态"
    exit 1
fi

# 检查容器是否存在
if ! docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
    echo "❌ 容器 ${CONTAINER_NAME} 不存在"
    echo "💡 请先运行 ./docker-run.sh 启动容器"
    exit 1
fi

# 显示容器状态
echo "📊 容器状态:"
docker ps -a --filter "name=${CONTAINER_NAME}" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
echo ""

# 显示日志
if [ "$FOLLOW" = "true" ] || [ "$FOLLOW" = "-f" ] || [ "$FOLLOW" = "--follow" ]; then
    echo "📝 实时日志 (按 Ctrl+C 退出):"
    echo ""
    docker logs -f --timestamps "${CONTAINER_NAME}"
else
    echo "📝 最近日志 (最后100行):"
    echo ""
    docker logs --timestamps --tail 100 "${CONTAINER_NAME}"
    echo ""
    echo "💡 查看实时日志: $0 -f"
fi 